{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import shutil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "shutil.rmtree(\"outdir\", ignore_errors = True) # start fresh each time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "sqft  = np.array([ 1000,    2000,    3000,    1000,  2000,  3000])\n",
    "ptype = np.array([\"house\", \"house\", \"house\", \"apt\", \"apt\", \"apt\"])\n",
    "price = np.array([ 500,     1000,    1500,    700,   1300,  1900])\n",
    "\n",
    "def nptrain_input_fn(sqft, ptype, price):  # a numpy array\n",
    "   return tf.estimator.inputs.numpy_input_fn(\n",
    "       x = {\"sq_footage\": sqft, \"type\": ptype},\n",
    "       y = price,\n",
    "       num_epochs=1000,\n",
    "       batch_size=3,\n",
    "       shuffle=True\n",
    "   )\n",
    "\n",
    "feat, lab = nptrain_input_fn(sqft, ptype, price)()\n",
    "\n",
    "featcols = [\n",
    "    tf.feature_column.numeric_column(\"sq_footage\"),\n",
    "    tf.feature_column.categorical_column_with_vocabulary_list(\"type\", [\"house\", \"apt\"])\n",
    "]\n",
    "    \n",
    "model = tf.estimator.LinearRegressor(featcols, \"outdir\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# try geting data from the input function by hand\n",
    "print(feat)\n",
    "with tf.Session() as sess:\n",
    "    tf.train.start_queue_runners(coord=tf.train.Coordinator())\n",
    "    a = sess.run(feat[\"sq_footage\"])\n",
    "    print(a)\n",
    "    a = sess.run(feat[\"sq_footage\"])\n",
    "    print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "#train model\n",
    "model.train(nptrain_input_fn(sqft, ptype, price))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
